//
//  RHDeviceSetCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/12/5.
//

#import "RHDeviceSetCell.h"
#import "RHButton.h"
@interface RHDeviceSetCell()

@end
@implementation RHDeviceSetCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    kWeakSelf;
    [self setBackgroundColor:CFTabViewBgColor];
    [self.contentView setBackgroundColor:CFTabViewBgColor];
    
    
    RHButton *dataBtn = [[RHButton alloc]initWithImage:@"device_data_monitor" title:@"数据监控".rh_localized];
    dataBtn.imageMargin = 12;
    dataBtn.imageTitleMargin = 10;
    dataBtn.backgroundColor = UIColor.whiteColor;
    dataBtn.layer.cornerRadius = 8;
    [self.contentView addSubview:dataBtn];
    [dataBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.mas_offset(0);
        make.width.offset((kUI_WINDOW_W-45)/2);
        make.height.offset(kScaleW(64));
    }];
    
    
    RHButton *setBtn = [[RHButton alloc]initWithImage:@"device_set_run" title:@"运行配置".rh_localized];
    setBtn.imageMargin = 12;
    setBtn.imageTitleMargin = 10;
    setBtn.backgroundColor = UIColor.whiteColor;
    setBtn.layer.cornerRadius = 8;
    [self.contentView addSubview:setBtn];
    [setBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dataBtn.mas_right).offset(15);
        make.top.equalTo(dataBtn);
        make.width.height.equalTo(dataBtn);
    }];
   
    if([self.reuseIdentifier isEqualToString:@"RHDeviceSetCell"]){
        RHButton *firmwareBtn = [[RHButton alloc]initWithImage:@"device_firmware" title:@"固件升级".rh_localized];
        firmwareBtn.btnTitleLab.textColor = kCOLOR_HEX(@"3F4443");
        firmwareBtn.backgroundColor = UIColor.whiteColor;
        firmwareBtn.layer.cornerRadius = 8;
       
        [self.contentView addSubview:firmwareBtn];
        [firmwareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(dataBtn);
            make.top.equalTo(dataBtn.mas_bottom).offset(15);
            make.height.equalTo(dataBtn);
            make.right.equalTo(setBtn);
            make.bottom.mas_offset(-15);
        }];
        
        UIImageView *arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow"]];
        [firmwareBtn addSubview:arrowImg];
        [arrowImg   mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(@(CGSizeMake(20, 20)));
            make.centerY.mas_offset(0);
            make.right.mas_offset(-15);
        }];
        
        UIView *pointView = kView;
        pointView.backgroundColor = kCOLOR_HEX(@"FA5555");
        [firmwareBtn addSubview:pointView];
        self.pointView = pointView;
        pointView.layer.cornerRadius = 4;
        [pointView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(8);
            make.right.equalTo(arrowImg.mas_left);
            make.centerY.mas_offset(0);
        }];
        
        [[firmwareBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
            if(weakSelf.firmwareBlock){
                weakSelf.firmwareBlock();
            }
        }];
    }
    
    
    
    
    [[dataBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.dataMonitorBlock){
            weakSelf.dataMonitorBlock();
        }
    }];
    
    [[setBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.paraSetBlock){
            weakSelf.paraSetBlock();
        }
    }];
    
    
}


//故障告警
-(UIView*)itemViewWithIndex:(NSInteger)idx title:(NSString*)title image:(NSString*)imageStr
{
    UIView *bgView = kView;
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    bgView.backgroundColor = UIColor.whiteColor;
    UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageStr]];
    [bgView addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(40);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(-15);
    }];
    
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.textAlignment = NSTextAlignmentLeft;
    titleLab.text = [NSString stringWithFormat:@"%@",title];
    titleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:1];
    titleLab.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:titleLab];
    
    QMUILabel *contentLab = [[QMUILabel alloc]init];
    contentLab.textAlignment = NSTextAlignmentLeft;
    contentLab.tag = 200 + idx;
    contentLab.text = @"--";
    contentLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:1];
    contentLab.font = [UIFont boldSystemFontOfSize:16];
    [bgView addSubview:contentLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-3);
        make.centerY.mas_offset(-12);
    }];
    
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleLab);
        make.centerY.mas_offset(12);
    }];
    return bgView;
}
@end
